
package com.jf.cloud.service.sysmanager.remote.api;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jf.cloud.service.sysmanager.common.base.OPaging;
import com.jf.cloud.service.sysmanager.common.util.StringUtil;
import com.jf.cloud.service.sysmanager.constant.UserConstant;
import com.jf.cloud.service.sysmanager.dao.IPubgExchangeGoodsService;
import com.jf.cloud.service.sysmanager.dao.IPubgUserService;
import com.jf.cloud.service.sysmanager.entity.PubgUser;
import com.jf.cloud.service.sysmanager.handler.TokenHandler;
import com.jf.cloud.service.sysmanager.support.entity.Result;
import com.jf.cloud.service.sysmanager.support.web.BaseController;

/**
 * 商城商品控制器
 * 
 * @author 代码机1.0 创建时间：2018-03-31
 */
@Controller
@RequestMapping("/appExchangeGoods")
public class AppPubgExchangeGoodsController extends BaseController {

	/**
	 * 日志
	 */
	private static Log log = LogFactory.getLog(AppPubgExchangeGoodsController.class);

	/**
	 * 商城商品服务
	 */
	@Resource
	private IPubgExchangeGoodsService pubgExchangeGoodsService;

	@Resource
	private IPubgUserService pubgUserService;
	
	@Resource
	private TokenHandler tokenHandler;
	
	/**
	 * 获取商城商品
	 * 
	 * @author 朱建文 创建时间：2018年4月11日 下午1:52:49
	 */
	@ResponseBody
	@RequestMapping("/getGoodsList")
	public Result<List<Map<String, Object>>> listPubgExchangeGoods(HttpServletRequest request, OPaging<Map<String, Object>> page) {
		Result<List<Map<String, Object>>> result = new Result<List<Map<String, Object>>>();
		result.setCode(-1);
		result.setMessage("获取商城商品失败！");
		try {
			String token = getParamValueString(request, "token");
			String userId = tokenHandler.getCommUserInfoByToken(token);
			if (userId == null || userId.trim().length() == 0) {
				result.setCode(-2);
				result.setMessage("请重新登陆！");
				return result;
			}

			// 每页数据条数
			int limit = getParamValueInteger(request, "limit", 50);
			page.setLimit(limit);

			// 第几页
			int offset = getParamValueInteger(request, "offset", -1);
			if (offset > 0) {
				page.setOffset((offset-1)*limit);
			}

			// 排序方式
			String order = getParamValueString(request, "order");
			if (StringUtil.isNotEmpty(order)) {
				page.setOrder(order);
			}

			// 排序字段
			String sort = getParamValueString(request, "sort");
			if (StringUtil.isNotEmpty(sort)) {
				page.setSort(sort);
			}
			
			List<Map<String, Object>> dataList = this.pubgExchangeGoodsService.getExchageGoodsList(page);
			result.setCode(0);
			result.setData(dataList);
			result.setMessage("获取商城商品成功！");
		} catch (Exception e) {
			log.error("前台获取商城商品出错！", e);
		}
		return result;
	}



}
